package com.yonyou.distribute.controller;

import com.yonyou.distribute.service.RedissonService_1;
import com.yonyou.distribute.service.RedissonService_2;
import com.yonyou.distribute.service.RedissonService_3;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class RedissonController {

    @Resource
    private RedissonService_1 redissonService_1;

    @Resource
    private RedissonService_2 redissonService_2;

    @Resource
    private RedissonService_3 redissonService_3;

    @GetMapping("/redisson/stock/deduct")
    public String deduct(){
        this.redissonService_1.deduct();
        return "hello stock deduct";
    }

    @GetMapping("/redisson2/stock/deduct")
    public String deduct2(){
        this.redissonService_2.deduct();
        return "hello stock deduct";
    }

    @GetMapping("/test/fair/lock/{id}")
    public String testFairLock(@PathVariable("id") Long id){
        redissonService_3.testFairLock(id);
        return "hello, test fair lock";
    }

    @GetMapping("/test/read/lock")
    public String testReadLock(){
        redissonService_3.testReadLock();
        return "hello, test testReadLock";
    }

    @GetMapping("/test/write/lock")
    public String testWriteLock(){
        redissonService_3.testWriteLock();
        return "hello, test testWriteLock";
    }

    @GetMapping("/test/semaphore")
    public String testSemaphore(){
        redissonService_3.testSemaphore();
        return "hello, semaphore";
    }

    @GetMapping("/test/latch")
    public String testLatch(){
        redissonService_3.testLatch();
        return "班长锁门了。。。。。";
    }

    @GetMapping("/test/countdown")
    public String testCountdown(){
        redissonService_3.testCountdown();
        return "出来一位同学。。。。";
    }
}
